﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nMongo.Tests
{
    [TestClass]
    public class MongoCollectionAtributeTests
    {
        [MongoCollection("AttributeTest")]
        public class AttrCollection
        {
            [BsonId(IdGenerator = typeof(GuidGenerator))]
            public Guid Id { get; set; }
        }

        [TestMethod]
        public void AttributeInitialization()
        {
            MongoEngine engine = new MongoEngine(TestsConfiguration.ConnectionString, TestsConfiguration.DatabaseName);
            MongoCollection<AttrCollection> collection = engine.GetCollection<AttrCollection>();
            collection.Insert(new AttrCollection());

            // Assert
            Assert.AreEqual(collection.Name, "AttributeTest");

            // Revert
            collection.RemoveAll();
            Assert.IsFalse(collection.AsQueryable().Any(x => x.Id != Guid.Empty));
        }
    }
}
